import java.util.Scanner;

public class demo02 {
    //数根
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str=sc.nextLine();
            while (str.length()>1){
                int sum=0;
                for (int i = 0; i < str.length(); i++) {
                    sum+=str.charAt(i)-'0';
                }
                str=String.valueOf(sum);
            }
            System.out.println(str);
        }
    }
}
